import {Base} from "../../../utils/base.js";

class Vod extends Base{
  constructor(){
    super()
  }

  /**
   * 列表
   * @param {*} success 
   * @param {*} fail 
   */
  getList(id,success,fail){
    this.request({
        url: '/chapter_list/'+id,
        success: function (res) {
            success && success(res)
        },
        fail:function(res){
            fail && fail(res)
        }
    })
  }

  /**
   * 详情
   * @param {*} id 
   * @param {*} success 
   * @param {*} fail 
   */
  getInfo(id,success,fail){
    this.request({
        url: '/chapter_info/'+id,
        success: function (res) {
            success && success(res)
        },
        fail:function(res){
            fail && fail(res)
        }
    })
  }

  /**
   * 设置当前播放时间
   * @param {*} data [vod_id,current_time]
   * @param {*} success 
   */
  setCurrentTime(data,success){
    this.request({
        url:'/vod_up_current_time',
        type:'POST',
        data:data,
        success:function(res){
            success && success(res)
        }
    })
  }

  /**
   * 视频结束
   * @param {*} id 
   * @param {*} success 
   */
  setEnd(id,success){
    this.request({
        url:'/vod_end/'+id,
        success:function(res){
            success && success(res)
        }
    })
  }

  /**
   * 获取视频观看用户
   */
  getVodUser(id,success){
    this.request({
        url:'/vod_user/'+id,
        success:function(res){
            success&&success(res)
        }
    })
  }

  /**
   * 验证用户是否可以播放词条视频
   * @param {*} data 
   * @param {*} success 
   * @param {*} fail 
   */
  checkVodAuth(data,success,fail){
      this.request({
          url:'/check_vod_auth',
          data,
          success:(res)=>{
              success&&success(res.data)
          },
          fail:(res)=>{
              fail&&fail(res)
          }
      })
  }

  /**
   * 收藏视频
   * @param {*} vod_id 
   * @param {*} success 
   */
  setVodCollect(vod_id,success,fail){
        this.request({
            url:'/set_vod_collect/'+vod_id,
            success:(res)=>{
                success&&success(res.data)
            },
            fail:(res)=>{
                fail&&fail(res.data)
            }
        })
  }

  /**
   * 视频搜索
   * @param {*} key 
   * @param {*} success 
   * @param {*} fail 
   */
  searchVod(key,success,fail){
    this.request({
        url:'/search_course',
        data:{key},
        success:(res)=>{
            success&&success(res.data)
        },
        fail:(res)=>{
            fail&&fail(res)
        }
    })
  }

}

export{Vod}